package com.ruoyi.user.service.impl;

import com.ruoyi.user.domain.UserOrderReview;
import com.ruoyi.user.domain.vo.OrderReviewDetailVO;
import com.ruoyi.user.mapper.UserOrderReviewsMapper;
import com.ruoyi.user.service.IUserOrderReviewsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.Date;

@Service
public class UserOrderReviewsServiceImpl implements IUserOrderReviewsService {

    @Resource
    private UserOrderReviewsMapper userOrderReviewsMapper;


    @Override
    public List<OrderReviewDetailVO> selectOrderReviewDetailsByMerchantId(Long merchantId) {
        return userOrderReviewsMapper.selectOrderReviewDetailsByMerchantId(merchantId);
    }

    @Override
    public OrderReviewDetailVO selectOrderReviewDetailById(Long reviewId) {
        return userOrderReviewsMapper.selectOrderReviewDetailById(reviewId);
    }

    @Override
    public List<OrderReviewDetailVO> selectOrderReviewDetailsByOrderId(Long orderId) {
        return userOrderReviewsMapper.selectOrderReviewDetailsByOrderId(orderId);
    }

    @Override
    public int insertOrderReview(UserOrderReview review) {
        Date now = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
        review.setCreatedAt(now);
        review.setUpdatedAt(now);
        return userOrderReviewsMapper.insertOrderReview(review);
    }
}
